package com.nononsenseapps.feeder.util

import androidx.core.net.toUri
import okhttp3.HttpUrl.Companion.toHttpUrl
import org.junit.Test
import timber.log.Timber
import java.net.URL
import kotlin.test.assertEquals

class LinkUtilsKtTest {

    @Test
    fun testSloppyToStrictAddsHttp() {
        assertEquals(URL("http://google.com"), sloppyLinkToStrictURL("google.com"))
    }

    @Test
    fun testSloppyToADVStrictAddsHttp() {
        assertEquals("www.google.com", LinkProtocolUtil.clearUrl("//www.google.com"))
        assertEquals("http://www.baidu.com", LinkProtocolUtil.getProtocol("//www.baidu.com"))
        assertEquals("http://www.baidu.com", LinkProtocolUtil.getProtocol("http://www.baidu.com"))
        assertEquals("http://www.baidu.com", LinkProtocolUtil.getProtocol("https://www.baidu.com"))
    }

    @Test
    fun testSloppyToStrictWithAlreadyValidLink() {
        assertEquals(URL("https://google.com"), sloppyLinkToStrictURL("https://google.com"))
    }

    @Test
    fun testSloppyToStrictWithEmptyString() {
        assertEquals(URL("http://"), sloppyLinkToStrictURL(""))
    }

    @Test
    fun testRelativeToAbsoluteWithFeedLinkAsBase() {
        assertEquals(URL("http://cowboy.com/bob.jpg"),
                relativeLinkIntoAbsoluteOrThrow(URL("http://cowboy.com/feed.xml"), "/bob.jpg"))
    }

    @Test
    fun testUrlToUri(){
        val httpUrl="http://cowboy.com/bob.jpg"
        val uri="content://sms//13868454561"
        println(httpUrl.toHttpUrl().toString())
        println(httpUrl.toHttpUrl().toUri().toString())

        var url=URL("http://feedin.wsl/content/sms/?")
        println("${url.protocol}-${url.host}-${url.path}-${url.query}")

        url=URL("http://feedin.wsl/dir/?/sdf/sdf/asf")
        println("${url.protocol}-${url.host}-${url.path}-${url.query}")

        url=URL("http://feedin.wsl/email/?test@email.com")
        println("${url.protocol}-${url.host}-${url.path}-${url.query}")

        url=URL("file://feedin.wsl/zip/?/sdf/sdf/asf.zip")
        println("${url.protocol}-${url.host}-${url.path}-${url.query}")

    }

}
